 package com.oanda.blackberry.view;
 
 import com.oanda.blackberry.restapi.LimitOrder;
 import com.oanda.blackberry.restapi.LimitOrderResponse;
 import com.oanda.blackberry.restapi.Quote;
 import com.oanda.blackberry.restapi.Symbol;
 import com.oanda.blackberry.ui.BitmapButtonField;
 import com.oanda.blackberry.ui.ColoredEditField;
 import com.oanda.blackberry.ui.ColoredObjectChoiceField;
 import com.oanda.blackberry.ui.CustomBitmapField;
 import com.oanda.blackberry.ui.OandaMainScreen;
 import com.oanda.blackberry.ui.QuoteChangeListener;
 import com.oanda.blackberry.ui.QuoteEditField;
 import com.oanda.blackberry.ui.SpacerField;
 import com.oanda.blackberry.ui.SpacerManager;
 import com.oanda.blackberry.ui.TradeLimitEditField;
 import com.oanda.blackberry.ui.TradeTypeChangeListener;
 import com.oanda.blackberry.util.AbstractViewPanel;
 import com.oanda.blackberry.util.DefaultController;
 import com.oanda.blackberry.util.Model;
 import com.oanda.blackberry.util.PropertyChangeEvent;
 import java.util.Vector;
 import net.rim.device.api.system.Application;
 import net.rim.device.api.system.Bitmap;
 import net.rim.device.api.ui.Field;
 import net.rim.device.api.ui.FieldChangeListener;
 import net.rim.device.api.ui.Font;
 import net.rim.device.api.ui.Manager;
 import net.rim.device.api.ui.MenuItem;
 import net.rim.device.api.ui.Screen;
 import net.rim.device.api.ui.UiApplication;
 import net.rim.device.api.ui.component.BasicEditField;
 import net.rim.device.api.ui.component.BitmapField;
 import net.rim.device.api.ui.component.ChoiceField;
 import net.rim.device.api.ui.component.Dialog;
 import net.rim.device.api.ui.component.EditField;
 import net.rim.device.api.ui.component.Menu;
 import net.rim.device.api.ui.component.ObjectChoiceField;
 import net.rim.device.api.ui.component.RadioButtonField;
 import net.rim.device.api.ui.component.RadioButtonGroup;
 import net.rim.device.api.ui.container.HorizontalFieldManager;
 import net.rim.device.api.ui.container.MainScreen;
 import net.rim.device.api.ui.decor.BackgroundFactory;
 
 public class NewOrderView
   implements AbstractViewPanel
 {
   DefaultController controller;
   BitmapButtonField submit = new BitmapButtonField(Bitmap.getBitmapResource("submit-button-hover.png"), Bitmap.getBitmapResource("submit-button-p8.png"), "Submit", 12884967424L);
 
   ColoredObjectChoiceField symbol = new ColoredObjectChoiceField(16119285, "", null, 100, 23);
   RadioButtonGroup sellBuyGroup = new RadioButtonGroup();
 
   HorizontalFieldManager operationFieldManager = new HorizontalFieldManager(1152921504606846976L);
   RadioButtonField sell = new RadioButtonField() { } ;
 
   RadioButtonField buy = new RadioButtonField();
 
   EditField bid = new EditField("Bid: ", "", 15, 9007199254740992L);
   EditField ask = new EditField("Ask: ", "", 15, 9007199254740992L);
 
   String[] expirityChoises = { "1 Hour", "2 Hours", "4 Hours", "8 Hours", "12 Hours", "16 Hours", "1 Day", "2 Days", "1 Week", "1 Month" };
 
   long[] expiryValues = { 3600L, 7200L, 14400L, 28800L, 43200L, 57600L, 86400L, 172800L, 604800L, 2592000L };
 
   int exptDefaultChoice = 8;
 
   ColoredObjectChoiceField expirity = new ColoredObjectChoiceField(16119285, 16119285, "", this.expirityChoises, 130, 22);
 
   ColoredEditField units = new ColoredEditField(16119285, 3355443, "", "", 15, 83886080L);
   ColoredEditField price = new ColoredEditField(16119285, 3355443, "", "", 15, 251658240L);
 
   TradeLimitEditField tp = new TradeLimitEditField(3355443, "", "", 13, 251658240L);
   TradeLimitEditField sl = new TradeLimitEditField(3355443, "", "", 13, 251658240L);
   TradeLimitEditField ts = new TradeLimitEditField(3355443, "", "", 13, 251658240L);
   TradeLimitEditField lb = new TradeLimitEditField(3355443, "", "", 13, 251658240L);
   TradeLimitEditField ub = new TradeLimitEditField(3355443, "", "", 13, 251658240L);
 
   QuoteEditField quoteField = new QuoteEditField(0L, null, 0);
   OandaMainScreen screen;
   CustomBitmapField c1;
   CustomBitmapField c2;
   CustomBitmapField c3;
   CustomBitmapField c4;
   CustomBitmapField c5;
   Vector tradeTypeChangeListeners = new Vector();
   Vector quoteChangeListeners = new Vector();
 
   MenuItem submitMenu = new MenuItem("Submit", 10, 1000)
   {
     public void run() {
       NewOrderView.this.submit();
     }
   };
 
   MenuItem back = new MenuItem("Back", 10, 1001)
   {
     public void run() {
       NewOrderView.this.controller.popScreen(NewOrderView.this.screen);
     }
   };
 
   public NewOrderView(DefaultController controller)
   {
     this.controller = controller;
   }
 
   private void init() {
     this.screen = new OandaMainScreen() {
       protected void makeMenu(Menu menu, int instance) {
         menu.add(NewOrderView.this.submitMenu);
         menu.add(NewOrderView.this.back);
       }
     };
     this.screen.getTitleManager().deleteAll();
 
     this.screen.getMainManager().setBackground(BackgroundFactory.createSolidBackground(4473924));
 
     createBackground();
     initFields();
 
     setFonts();
     setFieldsBg();
 
     this.sellBuyGroup.add(this.sell);
     this.sellBuyGroup.add(this.buy);
 
     this.sell.setMargin(3, 1, 1, 3);
     this.buy.setMargin(3, 1, 1, 3);
 
     this.screen.add(new SpacerField(480, 25));
     HorizontalFieldManager quoteM = new HorizontalFieldManager();
     this.symbol.setMargin(1, 0, 0, 10);
     quoteM.add(this.symbol);
     quoteM.add(this.quoteField);
     this.screen.add(quoteM);
 
     this.operationFieldManager.add(new SpacerField(140, 15));
     this.operationFieldManager.add(this.sell);
     this.operationFieldManager.add(new BitmapField(Bitmap.getBitmapResource("sell.png")));
     this.operationFieldManager.add(new SpacerField(62, 15));
     this.operationFieldManager.add(this.buy);
     this.operationFieldManager.add(new BitmapField(Bitmap.getBitmapResource("buy.png")));
     this.screen.add(this.operationFieldManager);
 
     HorizontalFieldManager details = new HorizontalFieldManager(1152921504606846976L);
     SpacerManager d1 = new SpacerManager(240, 60);
     SpacerManager d2 = new SpacerManager(240, 60);
 
     this.screen.add(details);
 
     details.add(d1);
     details.add(d2);
 
     HorizontalFieldManager uhm = new HorizontalFieldManager();
     BitmapField uBitmap = new BitmapField(Bitmap.getBitmapResource("units-label-72x30.png"));
     uhm.add(uBitmap);
     uhm.add(this.units);
 
     d1.add(uhm);
     uBitmap.setPadding(0, 0, 0, 0);
     this.units.setPadding(7, 8, 2, 15);
 
     HorizontalFieldManager ehm = new HorizontalFieldManager();
     BitmapField eBitmap = new BitmapField(Bitmap.getBitmapResource("expiry-label-72x30.png"));
     ehm.add(eBitmap);
     ehm.add(this.expirity);
     d1.add(new SpacerField(240, 2));
     d1.add(ehm);
     eBitmap.setPadding(0, 0, 0, 0);
     this.expirity.setPadding(3, 25, 2, 4);
     this.expirity.setMargin(0, 0, 1, 0);
 
     HorizontalFieldManager phm = new HorizontalFieldManager();
     BitmapField pBitmap = new BitmapField(Bitmap.getBitmapResource("quote-label-72x30.png"));
     phm.add(pBitmap);
     phm.add(this.price);
     d2.add(phm);
     pBitmap.setPadding(0, 0, 0, 0);
     this.price.setPadding(7, 8, 4, 15);
 
     this.screen.add(new BitmapField(Bitmap.getBitmapResource("separator-line-transperant-480-4.png"), 36028797018963968L));
     this.screen.add(new SpacerField(480, 2));
 
     HorizontalFieldManager limits = new HorizontalFieldManager(1152921504606846976L);
     SpacerManager v0LeftMargin = new SpacerManager(20, 50);
     SpacerManager v0 = new SpacerManager(20, 116);
     SpacerManager v1 = new SpacerManager(200, 116);
     SpacerManager v1RightMargin = new SpacerManager(22, 116);
     SpacerManager v11 = new SpacerManager(20, 116);
     SpacerManager v2 = new SpacerManager(200, 116);
     v0LeftMargin.setFocusable(false);
     v0.setFocusable(false);
     v11.setFocusable(false);
 
     limits.add(v0LeftMargin);
     limits.add(v0);
     limits.add(v1);
     limits.add(v1RightMargin);
     limits.add(v11);
     limits.add(v2);
 
     v0LeftMargin.add(new SpacerField(20, 1));
     v1RightMargin.add(new SpacerField(20, 1));
 
     this.c1 = new CustomBitmapField(Bitmap.getBitmapResource("symbol-selected-18x18-p24.png"), Bitmap.getBitmapResource("symbol-notselected-18x18.png"), "", 45035996273704960L);
 
     this.c2 = new CustomBitmapField(Bitmap.getBitmapResource("symbol-selected-18x18-p24.png"), Bitmap.getBitmapResource("symbol-notselected-18x18.png"), "", 9007199254740992L);
 
     this.c2 = new CustomBitmapField(Bitmap.getBitmapResource("symbol-selected-18x18-p24.png"), Bitmap.getBitmapResource("symbol-notselected-18x18.png"), "", 9007199254740992L);
 
     this.c3 = new CustomBitmapField(Bitmap.getBitmapResource("symbol-selected-18x18-p24.png"), Bitmap.getBitmapResource("symbol-notselected-18x18.png"), "", 9007199254740992L);
 
     this.c4 = new CustomBitmapField(Bitmap.getBitmapResource("symbol-selected-18x18-p24.png"), Bitmap.getBitmapResource("symbol-notselected-18x18.png"), "", 9007199254740992L);
 
     this.c5 = new CustomBitmapField(Bitmap.getBitmapResource("symbol-selected-18x18-p24.png"), Bitmap.getBitmapResource("symbol-notselected-18x18.png"), "", 9007199254740992L);
 
     v0.add(new SpacerField(1, 9));
     v0.add(this.c1);
     v0.add(new SpacerField(1, 14));
     v0.add(this.c2);
     v0.add(new SpacerField(1, 17));
     v0.add(this.c3);
     v11.add(new SpacerField(1, 9));
     v11.add(this.c4);
     v11.add(new SpacerField(1, 15));
     v11.add(this.c5);
 
     this.tp.setActiveListener(this.c1);
     this.sl.setActiveListener(this.c2);
     this.ts.setActiveListener(this.c3);
     this.ub.setActiveListener(this.c4);
     this.lb.setActiveListener(this.c5);
 
     this.tradeTypeChangeListeners = new Vector();
     this.quoteChangeListeners = new Vector();
 
     this.tradeTypeChangeListeners.addElement(this.tp);
     this.quoteChangeListeners.addElement(this.tp);
     this.tradeTypeChangeListeners.addElement(this.sl);
     this.quoteChangeListeners.addElement(this.sl);
     this.tradeTypeChangeListeners.addElement(this.ub);
     this.quoteChangeListeners.addElement(this.ub);
     this.tradeTypeChangeListeners.addElement(this.lb);
     this.quoteChangeListeners.addElement(this.lb);
     this.tradeTypeChangeListeners.addElement(this.ts);
     this.quoteChangeListeners.addElement(this.ts);
 
     this.tp.setTradeLimitType(0);
     this.ts.setTradeLimitType(2);
     this.ub.setTradeLimitType(3);
     this.sl.setTradeLimitType(1);
     this.lb.setTradeLimitType(4);
 
     this.screen.add(limits);
 
     this.tp.setPadding(6, 8, 3, 12);
     this.sl.setPadding(6, 8, 3, 12);
     this.ts.setPadding(6, 8, 3, 12);
 
     this.ub.setPadding(6, 8, 3, 12);
     this.lb.setPadding(6, 8, 3, 12);
 
     HorizontalFieldManager tpm = new HorizontalFieldManager();
     BitmapField tpBitmap = new BitmapField(Bitmap.getBitmapResource("tp-35x32.png"));
     tpm.add(tpBitmap);
     tpm.add(this.tp);
     tpBitmap.setPadding(0, 0, 2, 0);
     v1.add(tpm);
 
     HorizontalFieldManager slm = new HorizontalFieldManager();
     BitmapField slBitmap = new BitmapField(Bitmap.getBitmapResource("sl-35x32.png"));
     slm.add(slBitmap);
     slm.add(this.sl);
     slBitmap.setPadding(0, 0, 2, 0);
     v1.add(slm);
 
     HorizontalFieldManager tsm = new HorizontalFieldManager();
     BitmapField tsBitmap = new BitmapField(Bitmap.getBitmapResource("ts-35x32.png"));
     tsm.add(tsBitmap);
     tsm.add(this.ts);
     tsBitmap.setPadding(0, 0, 2, 0);
     v1.add(tsm);
 
     HorizontalFieldManager ubm = new HorizontalFieldManager();
     BitmapField ubBitmap = new BitmapField(Bitmap.getBitmapResource("ub-35x32.png"));
     ubm.add(ubBitmap);
     ubm.add(this.ub);
     ubBitmap.setPadding(0, 0, 2, 0);
     v2.add(ubm);
 
     HorizontalFieldManager lbm = new HorizontalFieldManager();
     BitmapField lbBitmap = new BitmapField(Bitmap.getBitmapResource("lb-35x32.png"));
     lbm.add(lbBitmap);
     lbm.add(this.lb);
     lbBitmap.setPadding(0, 0, 2, 0);
     v2.add(lbm);
 
     this.submit.setPadding(1, 0, 0, 0);
     this.screen.add(this.submit);
 
     this.quoteField.setChangeListener(new FieldChangeListener()
     {
       public void fieldChanged(Field field, int context)
       {
         if ((NewOrderView.this.symbol != null) && (NewOrderView.this.symbol.getSelectedIndex() != -1)) {
           int s = NewOrderView.this.symbol.getSelectedIndex();
           if (s + 1 == NewOrderView.this.symbol.getSize())
             s = 0;
           else {
             s++;
           }
           NewOrderView.this.symbol.setSelectedIndex(s);
         }
         NewOrderView.this.symbolFieldChanged();
       }
     });
     this.symbol.setChangeListener(new FieldChangeListener()
     {
       public void fieldChanged(Field field, int context)
       {
         NewOrderView.this.symbolFieldChanged();
       }
     });
     this.submit.setChangeListener(new FieldChangeListener()
     {
       public void fieldChanged(Field field, int context)
       {
         NewOrderView.this.submit();
       }
     });
     this.sell.setChangeListener(new FieldChangeListener() {
       public void fieldChanged(Field field, int context) {
         NewOrderView.this.tradeTypeChanged("sell");
       }
     });
     this.buy.setChangeListener(new FieldChangeListener() {
       public void fieldChanged(Field field, int context) {
         NewOrderView.this.tradeTypeChanged("buy");
       }
     });
     this.sellBuyGroup.setSelectedIndex(1);
     tradeTypeChanged("buy");
   }
 
   private void symbolFieldChanged()
   {
     int selected = this.symbol.getSelectedIndex();
     if ((selected > -1) && (this.symbol.getChoice(selected) != null) && 
       ((this.symbol.getChoice(selected) instanceof Quote))) {
       Quote q = (Quote)this.symbol.getChoice(selected);
       this.bid.setText(Double.toString(q.getBid()));
       this.ask.setText(Double.toString(q.getAsk()));
 
       this.quoteField.setQuote(q);
       notifyQuoteChangeListeners(q);
       this.screen.invalidate();
     }
   }
 
   private void tradeTypeChanged(String type)
   {
     notifyTradeTypeListeners(type);
   }
 
   private void notifyQuoteChangeListeners(Quote quote)
   {
     for (int i = 0; i < this.quoteChangeListeners.size(); i++) {
       QuoteChangeListener object = (QuoteChangeListener)this.quoteChangeListeners.elementAt(i);
       object.setQuote(quote);
     }
   }
 
   private void notifyTradeTypeListeners(String type) {
     for (int i = 0; i < this.tradeTypeChangeListeners.size(); i++) {
       TradeTypeChangeListener object = (TradeTypeChangeListener)this.tradeTypeChangeListeners.elementAt(i);
       object.setTradeType(type);
     }
   }
 
   private void submit()
   {
     Quote quote = Model.getModel().getRateQuotes()[this.symbol.getSelectedIndex()];
     if (quote == null) {
       DefaultController.inform("symbol is null");
       return;
     }
 
     String unitsValue = this.units.getText();
     int u = 0;
     if ((unitsValue == null) || ((unitsValue != null) && (unitsValue.length() == 0))) {
       DefaultController.inform("Error: Units must be greater than 0");
       return;
     }
     try {
       u = Integer.parseInt(unitsValue);
     }
     catch (NumberFormatException ne) {
     }
     if (4 != Dialog.ask(3, "Are you sure you want to create new order?")) {
       return;
     }
 
     String type = "";
     String tradeType = "";
     if (this.sellBuyGroup.getSelectedIndex() == 0) {
       type = "sell";
       tradeType = "short";
     } else {
       type = "buy";
       tradeType = "long";
     }
 
     String priceT = this.price.getText();
     double p = (0.0D / 0.0D);
     if ((priceT != null) && (priceT.length() > 0)) {
       try {
         p = Double.parseDouble(priceT);
       } catch (NumberFormatException ne) {
         DefaultController.inform("error in parsing price to double");
       }
     } else {
       DefaultController.inform("Error: Invalid quote price");
       return;
     }
 
     String lowerPrice = this.lb.getText();
     double lP = (0.0D / 0.0D);
     if ((this.lb.isActive()) && (lowerPrice != null) && (lowerPrice.length() > 0))
       try {
         lP = Double.parseDouble(lowerPrice);
       } catch (NumberFormatException ne) {
         DefaultController.inform("error in parsing lower bound to double");
       }
     else {
       lowerPrice = "";
     }
     String highPrice = this.ub.getText();
     double uP = (0.0D / 0.0D);
     if ((this.ub.isActive()) && (highPrice != null) && (highPrice.length() > 0))
       try {
         uP = Double.parseDouble(highPrice);
       } catch (NumberFormatException ne) {
         DefaultController.inform("error in parsing upper bound to double");
       }
     else {
       highPrice = "";
     }
     String stopLoss = this.sl.getText();
     double sL = (0.0D / 0.0D);
     if ((this.sl.isActive()) && (stopLoss != null) && (stopLoss.length() > 0))
       try {
         sL = Double.parseDouble(stopLoss);
       } catch (NumberFormatException ne) {
         DefaultController.inform("error in parsing stop loss to double");
       }
     else stopLoss = "";
 
     String takeProfit = this.tp.getText();
     double tP = (0.0D / 0.0D);
     if ((this.tp.isActive()) && (takeProfit != null) && (takeProfit.length() > 0))
       try {
         tP = Double.parseDouble(takeProfit);
       } catch (NumberFormatException ne) {
         DefaultController.inform("error in parsing takeProfit to double");
       }
     else takeProfit = "";
 
     String trailingStop = this.ts.getText();
     double tS = (0.0D / 0.0D);
     if ((this.ts.isActive()) && (trailingStop != null) && (trailingStop.length() > 0))
       try {
         tS = Double.parseDouble(trailingStop);
       } catch (NumberFormatException ne) {
         DefaultController.inform("error in parsing trailingStop to double");
       }
     else trailingStop = "";
     Symbol symbol = Model.getModel().getSymbol(quote.getSymbol());
     if (symbol == null) {
       DefaultController.inform("unable to find the symbol for the given quote.");
       return;
     }
 
     if (tS != (0.0D / 0.0D))
     {
       if (tS < 10.0D) {
         DefaultController.inform("Error: Trailing Stop must be at least 10 pips");
         return;
       }
 
       int intTS = 0;
       intTS = (int)symbol.getPippettes(tS);
       trailingStop = Integer.toString(intTS);
     }
 
     double pipLoc = symbol.getPiploc();
     LimitOrder order = new LimitOrder(Model.getModel().getActiveAccountId(), quote.getSymbol(), u, p, this.expiryValues[this.expirity.getSelectedIndex()], type, lP, uP, sL, tP, tS, pipLoc);
 
     String validationMessage = order.validate();
     if ((validationMessage != null) && (validationMessage.length() > 0))
     {
       DefaultController.inform(validationMessage);
       return;
     }
 
     long now = System.currentTimeMillis() + this.expiryValues[this.expirity.getSelectedIndex()] * 1000L;
     long unixExpiry = now / 1000L;
 
     this.controller.newOrder(Model.getModel().getActiveAccountId(), quote.getSymbol(), unitsValue, Double.toString(p), Long.toString(unixExpiry), type, lowerPrice, highPrice, stopLoss, takeProfit, trailingStop);
   }
 
   private void setQuotes(final Quote[] quote)
   {
     if (quote == null) return;
     if ((quote != null) && (quote.length == 0)) return;
     UiApplication.getUiApplication().invokeLater(new Runnable() { private final Quote[] _quote=quote;
 
       public void run() { NewOrderView.this.symbol.setChoices(this._quote);
         int selected = NewOrderView.this.symbol.getSelectedIndex();
         if (selected == -1) selected = 0;
         if (this._quote.length > selected) {
           NewOrderView.this.bid.setText(String.valueOf(this._quote[selected].getBid()));
           NewOrderView.this.ask.setText(String.valueOf(this._quote[selected].getAsk()));
 
           NewOrderView.this.quoteField.setQuote(this._quote[selected]);
           NewOrderView.this.screen.invalidate();
         }
       }
     });
   }
 
   public void modelPropertyChange(PropertyChangeEvent evt)
   {
     if (evt.getPropertyName().equals("setNewLimitOrderResponse")) {
       if ((evt.getNewValue() instanceof LimitOrderResponse)) {
         LimitOrderResponse response = (LimitOrderResponse)evt.getNewValue();
         DefaultController.showMessage("New Limit Order executed." + (response.getDir().equalsIgnoreCase("L") ? "\nBuying " : "\nSelling ") + Integer.toString(response.getUnits()) + " units of " + response.getSymbol() + " at " + Double.toString(response.getPrice()) + ".");
 
         initFields();
 
         Runnable r = new Runnable()
         {
           public void run()
           {
             NewOrderView.this.onClose();
           }
         };
         this.controller.invokeLater(r);
       }
       else {
         DefaultController.inform("Unable to parse TradeOrderResponse");
       }
     }
     else if (evt.getPropertyName().equals("newLimitOrderOpenBuy")) {
       init();
       setQuotes(Model.getModel().getRateQuotes());
       this.units.setFocus();
       this.controller.pushScreen(this.screen);
     }
     else if (evt.getPropertyName().equals("newLimitOrderOpenSell")) {
       init();
       setQuotes(Model.getModel().getRateQuotes());
       this.units.setFocus();
       this.controller.pushScreen(this.screen);
     }
   }
 
   public boolean onClose() {
     freeResources();
     this.controller.popScreen(this.screen);
     this.screen = null;
     return true;
   }
 
   private void setFonts() {
     this.ub.setFont(DefaultController.getComponentFont());
     this.lb.setFont(DefaultController.getComponentFont());
 
     this.tp.setFont(DefaultController.getComponentFont());
     this.ts.setFont(DefaultController.getComponentFont());
 
     this.sl.setFont(DefaultController.getComponentFont());
 
     this.sell.setFont(DefaultController.getComponentFont().derive(0, 22));
     this.buy.setFont(DefaultController.getComponentFont().derive(0, 22));
 
     this.units.setFont(DefaultController.getComponentFont());
     this.price.setFont(DefaultController.getComponentFont());
     this.expirity.setFont(DefaultController.getComponentFont());
 
     this.symbol.setFont(DefaultController.getComponentFont().derive(0, 22));
   }
 
   private void setFieldsBg() {
     Bitmap bg2 = Bitmap.getBitmapResource("limit-bg-transparent-166x31.png");
     Bitmap bg2Combo = Bitmap.getBitmapResource("custom-object-choiceField-166x27.png");
 
     this.tp.setBackground(BackgroundFactory.createBitmapBackground(bg2));
     this.ts.setBackground(BackgroundFactory.createBitmapBackground(bg2));
     this.ub.setBackground(BackgroundFactory.createBitmapBackground(bg2));
     this.lb.setBackground(BackgroundFactory.createBitmapBackground(bg2));
     this.sl.setBackground(BackgroundFactory.createBitmapBackground(bg2));
 
     this.units.setBackground(BackgroundFactory.createBitmapBackground(bg2));
     this.price.setBackground(BackgroundFactory.createBitmapBackground(bg2));
 
     this.expirity.setBackground(BackgroundFactory.createBitmapBackground(bg2Combo));
 
     this.tp.setTitleColor(8956419);
     this.ts.setTitleColor(16762898);
     this.ub.setTitleColor(8936959);
     this.lb.setTitleColor(8936959);
     this.sl.setTitleColor(14287362);
     this.units.setTitleColor(16119285);
     this.price.setTitleColor(16119285);
     this.expirity.setTitleColor(16119285);
 
     this.tp.setFontColor(3355443);
     this.ts.setFontColor(3355443);
     this.ub.setFontColor(3355443);
     this.lb.setFontColor(3355443);
     this.sl.setFontColor(3355443);
     this.units.setFontColor(3355443);
     this.price.setFontColor(3355443);
     this.expirity.setFontColor(3355443);
   }
 
   private void createBackground() {
     Bitmap bg = Bitmap.getBitmapResource("single-quote-header-480x400.png");
     this.screen.getMainManager().setBackground(BackgroundFactory.createBitmapBackground(bg));
   }
 
   private void initFields()
   {
     this.submit = new BitmapButtonField(Bitmap.getBitmapResource("submit-button-hover.png"), Bitmap.getBitmapResource("submit-button-p8.png"), "Submit", 12884967424L);
 
     this.symbol = new ColoredObjectChoiceField(16119285, "", null, 100, 23);
     this.sellBuyGroup = new RadioButtonGroup();
 
     this.operationFieldManager = new HorizontalFieldManager(1152921504606846976L);
     this.sell = new RadioButtonField()
     {
     };
     this.buy = new RadioButtonField();
 
     this.bid = new EditField("Bid: ", "", 15, 9007199254740992L);
     this.ask = new EditField("Ask: ", "", 15, 9007199254740992L);
 
     this.expirity = new ColoredObjectChoiceField(16119285, 16119285, "", this.expirityChoises, 130, 22);
 
     this.units = new ColoredEditField(16119285, 3355443, "", "", 15, 83886080L);
     this.price = new ColoredEditField(16119285, 3355443, "", "", 15, 251658240L);
 
     this.tp = new TradeLimitEditField(3355443, "", "", 15, 251658240L);
     this.sl = new TradeLimitEditField(3355443, "", "", 15, 251658240L);
     this.ts = new TradeLimitEditField(3355443, "", "", 15, 251658240L);
     this.lb = new TradeLimitEditField(3355443, "", "", 15, 251658240L);
     this.ub = new TradeLimitEditField(3355443, "", "", 15, 251658240L);
 
     this.quoteField = new QuoteEditField(0L, null, 0);
 
     this.tp.setText("");
     this.ts.setText("");
     this.ub.setText("");
     this.lb.setText("");
     this.sl.setText("");
 
     this.units.setText("");
     this.price.setText("");
     this.expirity.setSelectedIndex(0);
   }
 
   private void freeResources()
   {
     this.submit = null;
 
     this.symbol = null;
     this.sellBuyGroup = null;
 
     this.operationFieldManager = null;
     this.sell = null;
     this.buy = null;
 
     this.bid = null;
     this.ask = null;
 
     this.expirity = null;
 
     this.units = null;
     this.price = null;
 
     this.tp = null;
     this.sl = null;
     this.ts = null;
     this.lb = null;
     this.ub = null;
 
     this.quoteField = null;
   }
}

